package com.malty.mall.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.malty.mall.dao.pms.PmsProductCategoryMapper;
import com.malty.mall.domain.dto.req.UpdateStatusReq;
import com.malty.mall.domain.dto.req.pms.PmsProductCateParam;
import com.malty.mall.domain.entity.pms.PmsProductCategory;
import com.malty.mall.service.pms.IPmsProductCategoryService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author malty
 */
@Service
public class PmsProductCategoryServiceImpl extends ServiceImpl<PmsProductCategoryMapper, PmsProductCategory> implements IPmsProductCategoryService {
    @Override
    public Boolean create(PmsProductCateParam cateParam) {
        PmsProductCategory category = new PmsProductCategory(cateParam);
        return this.save(category);
    }

    @Override
    public Boolean updateCategoryById(PmsProductCateParam cateParam) {
        PmsProductCategory category = new PmsProductCategory(cateParam);
        return this.updateById(category);
    }

    @Override
    public Boolean updateShowStatus(UpdateStatusReq statusReq) {
        PmsProductCategory category = new PmsProductCategory();
        category.setShowStatus(statusReq.getStatus());
        return this.update(category, Wrappers.<PmsProductCategory>lambdaQuery().in(PmsProductCategory::getId, statusReq.getIds()));
    }

    @Override
    public Boolean updateNavStatus(UpdateStatusReq statusReq) {
        PmsProductCategory category = new PmsProductCategory();
        category.setNavStatus(statusReq.getStatus());
        return this.update(category, Wrappers.<PmsProductCategory>lambdaQuery().in(PmsProductCategory::getId, statusReq.getIds()));
    }

    @Override
    public PmsProductCateParam queryCateById(Integer id) {
        PmsProductCategory category = this.getById(id);
        return new PmsProductCateParam(category);
    }

    @Override
    public List<PmsProductCateParam> listById(Integer id) {
        List<PmsProductCategory> list = this.list(Wrappers.<PmsProductCategory>lambdaQuery().eq(PmsProductCategory::getParentId, id));
        return PmsProductCateParam.productCategoryParams(list);
    }

    @Override
    public Boolean deleteById(Long id) {
        return this.removeById(id);
    }

    @Override
    public List<PmsProductCateParam> listAll() {
        List<PmsProductCategory> list = this.list();
        return PmsProductCateParam.productCategoryParams(list);
    }
}
